//
//  LZRestaurantFiltersTextFiledCell.m
//  LzzizDemo
//
//  Created by xbnzd on 16/11/1.
//  Copyright © 2016年 xbnzd. All rights reserved.
//

#import "LZRestaurantFiltersTextFiledCell.h"

@interface LZRestaurantFiltersTextFiledCell()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UIButton *leftTextFiledBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightTextFiledBtn;

@end

@implementation LZRestaurantFiltersTextFiledCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.LeftMinTextFiled.delegate = self;
    self.RightMaxTextFiled.delegate = self;

    self.LeftMinTextFiled.layer.cornerRadius = 4;
    self.LeftMinTextFiled.layer.borderWidth = IS_IPHONE_6P?1:0.5;
    self.LeftMinTextFiled.layer.borderColor = UIColorFromRGB(0xdddddd, 1).CGColor;
    
    self.RightMaxTextFiled.layer.cornerRadius = 4;
    self.RightMaxTextFiled.layer.borderWidth = IS_IPHONE_6P?1:0.5;
    self.RightMaxTextFiled.layer.borderColor = UIColorFromRGB(0xdddddd, 1).CGColor;
}

#pragma mark -
#pragma mark 对外action
- (void)loadDataLeft:(NSString *)lStr
{
    if (_isForDatePicker) {
        self.leftTextFiledBtn.hidden = NO;
        self.rightTextFiledBtn.hidden = NO;
    }else{
        self.leftTextFiledBtn.hidden = YES;
        self.rightTextFiledBtn.hidden = YES;
    }
    
    self.LeftMinTextFiled.text = lStr;
}

- (void)loadDataRight:(NSString *)rStr
{
    if (_isForDatePicker) {
        self.leftTextFiledBtn.hidden = NO;
        self.rightTextFiledBtn.hidden = NO;
    }else{
        self.leftTextFiledBtn.hidden = YES;
        self.rightTextFiledBtn.hidden = YES;
    }
    self.RightMaxTextFiled.text = rStr;
}


- (void)setLeftTextFiledPlaceHolder:(NSString *)leftPHStr RightTextFiledPlaceHolder:(NSString *)rightPHStr
{
    if (_isForDatePicker) {
        self.leftTextFiledBtn.hidden = NO;
        self.rightTextFiledBtn.hidden = NO;
    }else{
        self.leftTextFiledBtn.hidden = YES;
        self.rightTextFiledBtn.hidden = YES;
    }
    self.LeftMinTextFiled.text = @"";
    self.RightMaxTextFiled.text = @"";
    self.LeftMinTextFiled.placeholder = leftPHStr;
    self.RightMaxTextFiled.placeholder = rightPHStr;
}

#pragma mark -
#pragma mark 弹出时间选择器
- (IBAction)leftBtnAction:(id)sender {
    if (self.textFiledCellDelegate && [self.textFiledCellDelegate respondsToSelector:@selector(ClickForDatePickerWithTextFiled:)]) {
        [self.textFiledCellDelegate performSelector:@selector(ClickForDatePickerWithTextFiled:) withObject:self.LeftMinTextFiled];
    }
}

- (IBAction)rightBtnAction:(id)sender {
    if (self.textFiledCellDelegate && [self.textFiledCellDelegate respondsToSelector:@selector(ClickForDatePickerWithTextFiled:)]) {
        [self.textFiledCellDelegate performSelector:@selector(ClickForDatePickerWithTextFiled:) withObject:self.RightMaxTextFiled];
    }
}

#pragma mark -
#pragma mark textfiled delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == self.LeftMinTextFiled) {
        [self.RightMaxTextFiled becomeFirstResponder];
        return YES;
    }
    
    [textField resignFirstResponder];
    
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField == self.LeftMinTextFiled) {
        if (self.textFiledCellDelegate) {
            [self.textFiledCellDelegate textFiledEditEnd:self.LeftMinTextFiled];
        }
    }
    
    if (self.textFiledCellDelegate) {
        [self.textFiledCellDelegate textFiledEditEnd:self.RightMaxTextFiled];
    }

}

@end
